function trim(val)
{
	 return val.replace(/(^\s*)|(\s*$)/g, "");  
}
 
function isMaxLen(o)
{  
	 var nMaxLen=o.getAttribute? parseInt(o.getAttribute("maxlength")):"";  
	 if(o.getAttribute && o.value.length>nMaxLen)
	 {      
	 	  o.value=o.value.substring(0,nMaxLen);  
	 }  
}
 
 
  
function selectAll(){
	var checkall = document.getElementById('checkall');
	var listsize = document.getElementById('listsize').value;
	for(var i=0;i<listsize;i++){
		if(checkall.checked){
			document.getElementById('checkone'+i).checked = true;
		}else{
			document.getElementById('checkone'+i).checked = false;
		}
	}
}

function judgeCheck()
{
    var pkid_string = '';
		var listsize = document.getElementById('listsize').value;
		for(var i=0;i<listsize;i++)
		{
				if(document.getElementById('checkone'+i).checked)
				{
					pkid_string += document.getElementById('checkone'+i).value+'|';
				}
		}
    return pkid_string;
}

function setGoodsType(val)
{
  if(val=='2')
  {
    document.getElementById('p_d').style.display ='inline';
  }else{
    document.getElementById('p_d').style.display ='none';
  }
}


function changeTime(val){

	var obj = document.getElementById(val+'_operating').value;
	if( obj == '' || obj.indexOf('-')>-1 || obj=='c' || obj=='d'||obj=='ship_none' || obj=='ship_start'|| obj=='ship_end'){
		document.getElementById(val+'_g').style.display = 'none';
	}else{
		document.getElementById(val+'_g').style.display = 'inline';
	}
}

function updatestate(val){
	var oper = document.getElementById(val+'_operating').value;
	var listsize = document.getElementById('listsize').value;
	var ifcomment='';
	var pkid_string = '';
	for(var i=0;i<listsize;i++){
		if(document.getElementById('checkone'+i).checked){
			pkid_string += document.getElementById('checkone'+i).value+'|';
		}
	}
	document.getElementById('pkid').value = pkid_string;
	if(pkid_string == ''){
		alert('请选择要操作的信息!');
		return false;
	}
	if(oper =='')
	{
	  alert('请选择操作方式!');
	  return false;
	}
	else if(oper=='ship_none' || oper=='ship_start'|| oper=='ship_end')
	{
	   
	   document.getElementById('pkid').value = pkid_string;
	   document.getElementById('state_code').value = oper;
	   document.getElementById('bpm_id').value = '3934';
	   document.indexForm.action='/doTradeReg.do';
	   if(window.confirm('确认提交吗?'))
	   {
			
		  document.indexForm.submit();
	   }
	}		
	else if(oper == '-')
	{
	   document.getElementById('pkid').value = pkid_string;
	   document.indexForm.action='/doTradeReg.do';
	   if(window.confirm('确认删除?'))
	   {
		  document.indexForm.submit();
	   }
	}
	else if(oper=='c' || oper=='d')
	{
	   
	   document.getElementById('pkid').value = pkid_string;
	   document.getElementById('state_code').value = oper;
	   document.getElementById('bpm_id').value = '6987';
	   document.indexForm.action='/doTradeReg.do';
	   if(window.confirm('确认提交吗?'))
	   {
		  document.indexForm.submit();
	   }
	}
	else
	{
	    document.getElementById('pkid').value = pkid_string;
		document.getElementById('up_operating').value = oper;
		document.getElementById('s_start_date').value = document.getElementById(val+'_start_date').value;
		document.getElementById('s_end_date').value = document.getElementById(val+'_end_date').value;
		document.indexForm.action='/doTradeReg.do';
		document.getElementById('bpm_id').value = '2491';
		if(window.confirm('确认提交吗?'))
		{
			document.indexForm.submit();
		}
	
	 }
}


function deleteOneInfo(pkid,bpm_id)
{
 
	if(window.confirm('确认删除吗？'))
	{
	  window.location.href='/doTradeReg.do?pkid='+pkid+'&bpm_id='+bpm_id;
 	}
}


function subForm(){
	
  if(trim(document.getElementById('title').value)=="")
  {
      alert('请输入标题！');
	  document.getElementById('title').focus();
      return; 
  }
  if(trim(document.getElementById('src_code').value)=='')
  {
      alert('请输入信息编号！');
	  document.getElementById('src_code').focus();
      return; 
  }
  if(trim(document.getElementById('src_type').value)=='')
  {
      alert('请选择车源类型！');
	  document.getElementById('src_type').focus();
      return; 
  }
  if(trim(document.getElementById('car_belong').value)=='')
  {
      alert('请选择车源所属！');
	  document.getElementById('car_belong').focus();
      return; 
  } 
  if(document.getElementById('startprovince').value!=''){
		var area_attr_str = '';
		area_attr_str += document.getElementById('startprovince').value+'|';
		if(document.getElementById('starteparchy_code').value!=''){
			area_attr_str += document.getElementById('starteparchy_code').value+'|';
			if(document.getElementById('startcity_code').value!=''){
				area_attr_str += document.getElementById('startcity_code').value+'|';
			}
		}
		if(area_attr_str == ''){
			alert('请选择出发地点！');
			return;
		}
		document.getElementById('start_addr').value = area_attr_str;
	}
	
	if(document.getElementById('endprovince').value!=''){
		var area_attr_str = '';
		area_attr_str += document.getElementById('endprovince').value+'|';
		if(document.getElementById('endeparchy_code').value!=''){
			area_attr_str += document.getElementById('endeparchy_code').value+'|';
			if(document.getElementById('endcity_code').value!=''){
				area_attr_str += document.getElementById('endcity_code').value+'|';
			}
		}
		if(area_attr_str == ''){
			alert('请选择目的地！');
			return;
		}
		document.getElementById('end_addr').value = area_attr_str;
	}
  if(trim(document.getElementById('contact').value)=='')
  {
      alert('请输入联系人！');
	  document.getElementById('contact').focus();
      return; 
  }
  if(trim(document.getElementById('cellphone').value)=='')
  {
      alert('请输入手机号码！');
	  document.getElementById('cellphone').focus();
      return; 
  }
  
  document.addForm.submit();    

}

 

function audit(val){
	if(val == 1){
		document.getElementById('state_code').value = 'c';
	}
	if(val == 2){
		document.getElementById('state_code').value = 'b';
		alert(document.getElementById('state_code').value);
	}
	document.addForm.submit();
}


function ChangeAreaStyleS(){
	document.getElementById("start_addr").value = '';
	document.getElementById("areaId1").style.display = 'none';
	document.getElementById("areaId2").style.display = 'block';
}
function ChangeAreaStyleE(){
	document.getElementById("end_addr").value = '';
	document.getElementById("areaId3").style.display = 'none';
	document.getElementById("areaId4").style.display = 'block';
}


function setstartProvince()
{
	Ts_areaInfo.getAreaClassByUpId('000000000000000',function(data){
		DWRUtil.removeAllOptions('startprovince');
		DWRUtil.addOptions('startprovince',{'':'请选择'});
		DWRUtil.addOptions('startprovince',data);
	})
}


function setendProvince()
{
	Ts_areaInfo.getAreaClassByUpId('000000000000000',function(data){
		DWRUtil.removeAllOptions('endprovince');
		DWRUtil.addOptions('endprovince',{'':'请选择'});
		DWRUtil.addOptions('endprovince',data);
	})
}
function setCitys(prov,val)
{var provence=prov;
	 Ts_areaInfo.getAreaClassByUpId(provence,function(data){
		DWRUtil.removeAllOptions(val+'eparchy_code');
		DWRUtil.addOptions(val+'eparchy_code',{'':'请选择'});
		DWRUtil.addOptions(val+'eparchy_code',data);
		DWRUtil.removeAllOptions(val+'city_code');
		DWRUtil.addOptions(val+'city_code',{'':'请选择'});
	});
}

function setAreas(city_id,val){
	Ts_areaInfo.getAreaClassByUpId(city_id,function(data){
	 	DWRUtil.removeAllOptions(val+'city_code');
		DWRUtil.addOptions(val+'city_code',{'':'请选择'});
	 	DWRUtil.addOptions(val+'city_code',data);
	});
}


function searcher(){

   var start_attr=""; 
  if(document.getElementById("startprovince").value!="")
  {
      start_attr = document.getElementById("startprovince").value+"|"; 
  }

  if(document.getElementById("starteparchy_code").value!="")
  {
      start_attr += document.getElementById("starteparchy_code").value+"|"; 
  }

  if(document.getElementById("startcity_code").value!="")
  {
      start_attr += document.getElementById("startcity_code").value+"|"; 
  }
  
  var end_attr=""; 
  if(document.getElementById("endprovince").value!="")
  {
      end_attr = document.getElementById("endprovince").value+"|"; 
  }

  if(document.getElementById("endeparchy_code").value!="")
  {
      end_attr += document.getElementById("endeparchy_code").value+"|"; 
  }

  if(document.getElementById("endcity_code").value!="")
  {
      end_attr += document.getElementById("endcity_code").value+"|"; 
  }
  
  document.getElementById("end_addr").value = end_attr;
  document.getElementById("start_addr").value = start_attr;
  
	document.indexForm.submit();
}	
	
